import
java.awt.Button;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
public class SimulateClick
{
/**
* A function to simulate a click on the target button.
* This will make the button draw as if it had been pressed and
* released, and the button will fire an Action event as if
* the button were pressed.
* For use with the Apple MRJ 2.1 EA3 and later.
*/
static protected void simulateClick(Button target)
{
if (target != null)
{
KeyEvent keyEvent =
new KeyEvent(target, KeyEvent.KEY_PRESSED,
System.currentTimeMillis(), 0, KeyEvent.VK_ENTER,
(char)KeyEvent.VK_ENTER);
target.dispatchEvent(keyEvent);
}
}
}
|